// pages/farmerend/onsalesrecordsTap/onsalesrecordsTap.js
var utils = require('../../../utils/util.js');
var app=getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        currentPage:1,
        date:""
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var that = this;
        console.log(options.type)
        var currentdate = utils.formatdate(new Date());
        that.setData({
            currentdate: currentdate,
            date: currentdate,
            type:options.type
        })
        that.onSalesList(that.data.currentPage,that.data.date);
    },
    onShow:function(){
        var that=this;
        if(that.data.type==1){
            wx.setNavigationBarTitle({
                title: '销售记录'
            })
        }else{
            wx.setNavigationBarTitle({
                title: '售后记录'
            })
        }
      
    },
    bindDateChange(e) {
        var that=this;
        console.log('picker发送选择改变，携带值为', e.detail.value)
        this.setData({
            date: e.detail.value,
            currentPage:1,
            list:[]
        })
        that.onSalesList(that.data.currentPage, that.data.date);
    },

    //列表记录
    onSalesList: function (currentPage,date){
        utils.showLoading();
        var that = this;
        var url=""
        if (that.data.type==1){
            url = "/api/v1/storemanage/order_sale"
        }else{
            url ="/api/v1/storemanage/order_back"
        }
        utils.http(url, { page: currentPage, date: date, store_id: wx.getStorageSync("userType").storeid},function(res){
            utils.hideLoading();
            var allpost = that.data.list;
            if (allpost == undefined) {
                allpost = [];
            }
            for (var i in res.datas.list) {
                allpost.push(res.datas.list[i]);
            }
            if (res.datas.list.length < 10) {
                that.setData({
                    tishi_title: '已加载全部',
                });
            } else {
                that.setData({
                    tishi_title: '加载更多',
                });
            }
            that.setData({
                list: allpost,
                total_count: res.datas.total_count,
                ready: res.datas.length == 0 ? 1 : 2,
            })
        })
    },
    /**
* 页面上拉触底事件的处理函数
*/
    onReachBottom: function () {
        var that = this;
        if (that.data.ready == 2) {
            var page = that.data.currentPage + 1
            that.setData({
                currentPage: page,
            })
            that.onSalesList(page,that.data.date)
        }

    },
})